package com.soujiayi.activity;

import com.soujiayi.util.Constants;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.TextView;
import android.widget.Toast;

public class TuanDetailWebActivity extends Activity {

	private WebView wv_tuan_web;
	final Activity context = this;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		((MyApplication) this.getApplication()).addActivity(this);
		requestWindowFeature(Window.FEATURE_PROGRESS);
		this.setContentView(R.layout.tuan_detail_web);
		wv_tuan_web = (WebView) findViewById(R.id.wv_tuan_web);
		wv_tuan_web.getSettings().setJavaScriptEnabled(true);
		
		String productName = this.getIntent().getStringExtra(Constants.PRODUCT_NAME);
		if(productName != null && productName.length() > 10){
			productName = productName.substring(0, 10) + "...";
		}
		TextView productNameView = (TextView) findViewById(R.id.tuan_webview_productName);
		productNameView.setText(productName == null ? "": productName);

		wv_tuan_web.setWebChromeClient(new WebChromeClient() {
			public void onProgressChanged(WebView view, int progress) {
				// Activity和Webview根据加载程度决定进度条的进度大小
				// 当加载到100%的时候 进度条自动消失
				context.setProgress(progress * 100);
			}
		});
		
		wv_tuan_web.loadUrl(this.getIntent().getStringExtra(Constants.TUAN_DETAIL_URL));
	}

	public void backToHome(View view) {
		Intent intent = new Intent(TuanDetailWebActivity.this,
				IndexActivity.class);
		startActivity(intent);
		this.finish();
		overridePendingTransition(R.anim.push_down_in, R.anim.push_down_out);
	}

	public void back(View view) {
		this.finish();
		overridePendingTransition(R.anim.push_down_in, R.anim.push_down_out);
	}

	@Override
	public void onBackPressed() {
		// TODO Auto-generated method stub
		super.onBackPressed();
		this.finish();
		overridePendingTransition(R.anim.push_down_in, R.anim.push_down_out);
	}
	
}
